<template>
  <div class="app-container">
    <ht-table
      ref="dataTable"
      :multi-select="false"
      :showSerialNumber="false"
      :dictMap="dictMap"
      :queryParams="queryParams"
      :tableBindColumns="tableBindColumns"
      :opButtonList="opButtonList"
      :reqConfig="regConfig"
      :randomRowKey="true"
    >
      <template v-slot:operate>
        <el-table-column label="操作" align="left" width="50" fixed="right">
          <template slot-scope="scope">
            <ht-button-group
              :buttonList="[
                {
                  label: '维护',
                  doFunc: () => {
                    handleAction('detail', scope.row);
                  },
                },
              ]"
            />
          </template>
        </el-table-column>
      </template>
    </ht-table>

    <!-- 添加或修改弹出框 -->
    <el-dialog
      :title="title"
      center
      :visible.sync="open"
      v-if="open"
      width="1024px"
      :destroy-on-close="true"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <el-form ref="detailForm" :rules="rules" :model="detailForm" label-width="110px">
        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="交易流水号" prop="reqId">
              <el-input v-model="detailForm.reqId" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="报文标识号" prop="reqPkgid">
              <el-input v-model="detailForm.reqPkgid" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="工作日期" prop="reqWorkdate">
              <el-date-picker
                style="width: 100%"
                v-model="detailForm.reqWorkdate"
                value-format="yyyyMMdd"
                type="date"
                :disabled="true"
              />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="退回类型" prop="backType">
              <el-select style="width: 100%" v-model="detailForm.backType" placeholder="退回类型" :disabled="true">
                <el-option
                  v-for="dict in dictMap.RETURNTYPECODE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="发起参与机构" prop="reqSender">
              <el-input v-model="detailForm.reqSender" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发起参与机构名称" prop="reqSenderName">
              <el-input v-model="detailForm.reqSenderName" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item
              label="原报文标识号"
              prop="oriPkgid"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-input v-model="detailForm.oriPkgid" :disabled="true" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item
              label="原交易流水号"
              prop="oriId"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-input v-model="detailForm.oriId" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item
              label="原报文类型"
              prop="oriPkgtype"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-select style="width: 100%" v-model="detailForm.oriPkgtype" placeholder="原报文类型" :disabled="true">
                <el-option
                  v-for="dict in dictMap.PKG_TYPE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item
              label="退回附言"
              prop="oriRemarks"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-input v-model="detailForm.oriRemarks" :disabled="true" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item
              label="交易渠道"
              prop="reqSource"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-select style="width: 100%" v-model="detailForm.reqSource" placeholder="柜面交易" :disabled="true">
                <el-option
                  v-for="dict in dictMap.TXN_SOURCE"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              label="接收时间"
              prop="rcvTime"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-date-picker
                style="width: 100%"
                v-model="detailForm.rcvTime"
                value-format="yyyyMMddhhmmss"
                type="datetime"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item
              label="通讯状态"
              prop="status"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-select style="width: 100%" v-model="detailForm.status" placeholder="通讯状态" :disabled="true">
                <el-option
                  v-for="dict in dictMap.PKG_STATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item
              label="中心状态"
              prop="procStatus"
              v-if="detailForm.backType === 'RP00' || detailForm.sysCode === 'HVPS'"
            >
              <el-select style="width: 100%" v-model="detailForm.procStatus" placeholder="中心状态" :disabled="true">
                <el-option
                  v-for="dict in dictMap.PROCESSSTATUS"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <ht-table
              ref="bepsdataTable"
              v-if="detailForm.backType === 'RP01' && detailForm.sysCode === 'BEPS'"
              :multi-select="false"
              :showSerialNumber="false"
              :dictMap="dictMap"
              :queryParams="queryParams"
              :tableBindColumns="bepstableBindColumns"
              :reqConfig="bepsregConfig"
              :showRightToolbar="false"
              :default-event-key="defaultEventKey"
            />
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="12">
            <el-form-item label="退回应答结果" prop="backResult">
              <el-select style="width: 100%" clearable v-model="detailForm.backResult" placeholder="退回应答结果">
                <el-option
                  v-for="dict in dictMap.RET_ANSWER_RP00"
                  :key="dict.value"
                  :label="`${dict.value}-${dict.text}`"
                  :value="dict.value"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row type="flex">
          <el-col :span="24">
            <el-form-item
              label="附言"
              prop="remarks"
              :rules="{
                required: this.detailForm.backType === 'RP00' || this.detailForm.sysCode === 'HVPS' ? true : false,
                message: '请输入退回附言',
                trigger: 'blur',
              }"
            >
              <el-input v-model="detailForm.remarks" type="textarea" maxlength="100" show-word-limit/>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" align="center">
        <el-button type="primary" @click="submitForm" v-loading.fullscreen.lock="loading">提 交</el-button>
        <el-button @click="refresh">重 置</el-button>
        <el-button @click="cancel">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  apiUrlConfigQuery,
  bepsapiUrlConfigQuery,
  ccmsBusinessReturnResponseEntryDeatil,
  ccmsBusinessReturnResponseEntrySave,
} from "@/api/cnaps/ccms/319";
import { listPageMixin } from "@/libs/listPageMixin";
import { findFreeEntry } from "@/api/cnaps/ccms/303";
import { resetForm } from "@/utils/ruoyi";

export default {
  name: "CcmsBusinessReturnResponseEntry",
  mixins: [listPageMixin],
  components: {},
  data() {
    return {
      defaultEventKey: "bepsEventKey",
      loading: false,
      queryParams: {
        reqId: undefined,
      },
      // 搜索
      formOptions: [],
      //
      searchFormDictList: [
        "PKG_TYPE",
        "TXN_SOURCE",
        "PKG_STATUS",
        "RETURNTYPECODE",
        "PROCESSSTATUS",
        "RET_ANSWER_RP00",
        "BIZ_TYPE",
      ],
      // 列信息
      regConfig: apiUrlConfigQuery,
      tableBindColumns: [
        { prop: "reqId", label: "交易流水号", align: "center", width: "200" },
        { prop: "reqWorkdate", label: "工作日期", align: "center", type: "date" },
        { prop: "reqSource", label: "来源", align: "center", dictCode: "TXN_SOURCE" },
        { prop: "reqSender", label: "发起参与机构", align: "center" },
        { prop: "oriPkgid", label: "原报文标识号", align: "center" },
        { prop: "oriPkgtype", label: "原报文类型", align: "center", dictCode: "PKG_TYPE", width: "300" },
        { prop: "reqSource", label: "来源", align: "center", dictCode: "PKG_STATUS" },
      ],

      bepsregConfig: bepsapiUrlConfigQuery,
      bepstableBindColumns: [
        { prop: "id", label: "交易流水号", sortable: false },
        { prop: "txnOriDtlNo", label: "原明细标识号", sortable: false },
        { prop: "coreId", label: "原交易流水号", sortable: false },
        { prop: "txnOriDirectSender", label: "原交易发起直接参与机构", sortable: false },
        { prop: "txnOriDirectRecver", label: "原交易接收直接参与机构号", sortable: false },
        { prop: "oriBizCode", label: "原业务类型编码", dictCode: "BIZ_TYPE", sortable: false },
      ],

      rules: {
        backResult: [{ required: true, message: "请输入退回应答结果", trigger: "blur" }],
      },

      dictMapAsync: {},
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      detailForm: {
        backType: undefined,
        sysCode: undefined,
        // remarks: undefined,
        // backResult:undefined
      },
      totalRecord: 0,
      totalPage: 0,
      needCount: 0,
    };
  },
  mounted() {},
  methods: {
    /***
     * 按钮操作汇总
     */
    /***
     * 按钮操作汇总
     */
    handleAction(type, row = {}) {
      switch (type) {
        case "detail":
          this.handleDetail(row);
          break;
      }
    },

    // 关闭按钮
    cancel() {
      this.open = false;
    },

    /** 详情按钮操作 */
    handleDetail(row) {
      this.title = "业务退回应答录入维护";
      ccmsBusinessReturnResponseEntryDeatil(row).then((response) => {
        this.open = true;
        this.detailForm = response.result;
        this.$set(this.detailForm, "backResult", "");
        this.$set(this.detailForm, "remarks", "");
        if (row.oriPkgtype !== null) {
          const sysCode = row.oriPkgtype.substring(0, 4).toUpperCase();
          this.detailForm.sysCode = sysCode;
        }
        this.detailForm.backType = row.backType;
        this.queryParams.reqId = this.detailForm.reqId;
      });
    },

    /** 提交按钮 */
    submitForm: function () {
      this.$refs["detailForm"].validate((valid) => {
        if (valid) {
          this.loading = true;
          ccmsBusinessReturnResponseEntrySave(this.detailForm)
            .then((response) => {
              this.msgSuccess("录入成功");
              this.refresh();
              this.open = false;
              this.loading = false;
              this.$nextTick(() => {
                this.$refs.dataTable.doQuery(true);
              });
            })
            .catch((err) => {
              this.loading = false;
            });
        }
      });
    },
    //点击重置按钮
    refresh() {
      this.resetForm("detailForm");
    },
  },
};
</script>
